package com.avcdata.aoscustommade.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.view.View;

import com.avcdata.aoscustommade.R;

/**
 * Created by c.c on 2017/3/2.
 * 自定义虚线类
 */

public class DashedLine_View extends View {
    private Context context;

    public DashedLine_View(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;

    }

    @SuppressWarnings("deprecation")
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(context.getResources().getColor(R.color.text_one));//颜色可以自己设置
        Path path = new Path();
        path.moveTo(0, 0);//起始坐标
        path.lineTo(0, 500);//终点坐标
        PathEffect effects = new DashPathEffect(new float[]{8, 8, 8, 8}, 2);//设置虚线的间隔和点的长度
        paint.setPathEffect(effects);
        canvas.drawPath(path, paint);
    }


}
